﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SecurityApi.Business
{
    public class ApplicationManager
    {
        public int AddApplication(SecurityApi.Model.Application application)
        {
            return 0;
        }

        public bool RemoveApplication(SecurityApi.Model.Application application)
        {
            return false;
        }

        public  IQueryable<SecurityApi.Model.Application> GetAllApplications()
        {
            SecurityApi.DataAccess.ApplicationRepository repository = new SecurityApi.DataAccess.ApplicationRepository();
            IQueryable<SecurityApi.Model.Application> apps = repository.GetAll();
            return apps;
        }

        public SecurityApi.Model.Application GetApplicationById(int appId)
        {
            SecurityApi.DataAccess.ApplicationRepository repository = new SecurityApi.DataAccess.ApplicationRepository();
            SecurityApi.Model.Application apps = repository.GetAll().Where(p => p.ApplicationId == appId).SingleOrDefault();
            return apps;
        }


        public List<SecurityApi.Model.Application> GetEnterpriseApplications(long enterpriseId)
        {
            SecurityApi.DataAccess.ApplicationRepository repository = new SecurityApi.DataAccess.ApplicationRepository();
            IQueryable<SecurityApi.Model.Application> query = repository.GetAll().Where(p => p.Enterprise.Id == enterpriseId).OrderBy(p=>p.ApplicationId);
            List<SecurityApi.Model.Application> enterpriseApps = query.ToList();
            return enterpriseApps;
        }

    }
}
